package com.csu.mining.adapters;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;

import com.csu.mining.R;
import com.csu.mining.activity.BaseActivity;
import com.csu.mining.activity.FileListActivity;
import com.csu.mining.activity.MainActivity;
import com.csu.mining.activity.PicListActivity;
import com.csu.mining.activity.VideoListActivity;
import com.csu.mining.views.WEqualsHImageView;

import java.util.ArrayList;
import java.util.List;

public class MiningBottomAdapter extends RecyclerView.Adapter<MiningBottomAdapter.ViewHolder> {

    private Context mContext;
    private String mActName;
    public MiningBottomAdapter(Context context,String actName){
        mContext = context;
        mActName = actName;
    }

    public void actBar(int position,ViewHolder viewHolder){
        switch (mActName){
            case "home":
                if(position==0) {
                    viewHolder.wEqualsHImageView.setImageResource(R.mipmap.home);
                    viewHolder.textView.setTextColor(ContextCompat.getColor(mContext, R.color.mainColor));
                    viewHolder.textView.setText(R.string.main_home);
                }else if(position==1) {
                    viewHolder.wEqualsHImageView.setImageResource(R.mipmap.message1);
                    viewHolder.textView.setTextColor(ContextCompat.getColor(mContext, R.color.context_color));
                    viewHolder.textView.setText(R.string.mov);
                }else if(position==2) {
                    viewHolder.wEqualsHImageView.setImageResource(R.mipmap.file2);
                    viewHolder.textView.setTextColor(ContextCompat.getColor(mContext, R.color.context_color));
                    viewHolder.textView.setText(R.string.file);
                }else if(position==3){
                    viewHolder.wEqualsHImageView.setImageResource(R.mipmap.user1);
                    viewHolder.textView.setTextColor(ContextCompat.getColor(mContext,R.color.context_color));
                    viewHolder.textView.setText(R.string.pic);
                }break;
            case "mov":
                if(position==0) {
                    viewHolder.wEqualsHImageView.setImageResource(R.mipmap.home2);
                    viewHolder.textView.setTextColor(ContextCompat.getColor(mContext, R.color.context_color));
                    viewHolder.textView.setText(R.string.main_home);
                }else if(position==1) {
                    viewHolder.wEqualsHImageView.setImageResource(R.mipmap.message);
                    viewHolder.textView.setTextColor(ContextCompat.getColor(mContext, R.color.mainColor));
                    viewHolder.textView.setText(R.string.mov);
                }else if(position==2) {
                    viewHolder.wEqualsHImageView.setImageResource(R.mipmap.file2);
                    viewHolder.textView.setTextColor(ContextCompat.getColor(mContext, R.color.context_color));
                    viewHolder.textView.setText(R.string.file);
                }else if(position==3){
                    viewHolder.wEqualsHImageView.setImageResource(R.mipmap.user1);
                    viewHolder.textView.setTextColor(ContextCompat.getColor(mContext,R.color.context_color));
                    viewHolder.textView.setText(R.string.pic);
                }break;
            case "file":
                if(position==0) {
                    viewHolder.wEqualsHImageView.setImageResource(R.mipmap.home2);
                    viewHolder.textView.setTextColor(ContextCompat.getColor(mContext, R.color.context_color));
                    viewHolder.textView.setText(R.string.main_home);
                }else if(position==1) {
                    viewHolder.wEqualsHImageView.setImageResource(R.mipmap.message1);
                    viewHolder.textView.setTextColor(ContextCompat.getColor(mContext, R.color.context_color));
                    viewHolder.textView.setText(R.string.mov);
                }else if(position==2) {
                    viewHolder.wEqualsHImageView.setImageResource(R.mipmap.file);
                    viewHolder.textView.setTextColor(ContextCompat.getColor(mContext, R.color.mainColor));
                    viewHolder.textView.setText(R.string.file);
                }else if(position==3){
                    viewHolder.wEqualsHImageView.setImageResource(R.mipmap.user1);
                    viewHolder.textView.setTextColor(ContextCompat.getColor(mContext,R.color.context_color));
                    viewHolder.textView.setText(R.string.pic);
                }break;
            case "pic":
                if(position==0) {
                    viewHolder.wEqualsHImageView.setImageResource(R.mipmap.home2);
                    viewHolder.textView.setTextColor(ContextCompat.getColor(mContext, R.color.context_color));
                    viewHolder.textView.setText(R.string.main_home);
                }else if(position==1) {
                    viewHolder.wEqualsHImageView.setImageResource(R.mipmap.message1);
                    viewHolder.textView.setTextColor(ContextCompat.getColor(mContext, R.color.context_color));
                    viewHolder.textView.setText(R.string.mov);
                }else if(position==2) {
                    viewHolder.wEqualsHImageView.setImageResource(R.mipmap.file2);
                    viewHolder.textView.setTextColor(ContextCompat.getColor(mContext, R.color.context_color));
                    viewHolder.textView.setText(R.string.file);
                }else if(position==3){
                    viewHolder.wEqualsHImageView.setImageResource(R.mipmap.user);
                    viewHolder.textView.setTextColor(ContextCompat.getColor(mContext,R.color.mainColor));
                    viewHolder.textView.setText(R.string.pic);
                }break;
        }
    }

    public void bindClick(ViewHolder viewHolder,int position){
        switch (position){
            case 0:
                viewHolder.wEqualsHImageView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent = new Intent(mContext, MainActivity.class);
                        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                        mContext.startActivity(intent);
                        ((Activity)mContext).overridePendingTransition(R.anim.no_animation,R.anim.no_animation);
                    }
                });break;
            case 1:
                viewHolder.wEqualsHImageView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent = new Intent(mContext, VideoListActivity.class);
                        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                        mContext.startActivity(intent);
                        ((Activity)mContext).overridePendingTransition(R.anim.no_animation,R.anim.no_animation);
                    }
                });break;
            case 2:
                viewHolder.wEqualsHImageView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent = new Intent(mContext, FileListActivity.class);
                        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                        mContext.startActivity(intent);
                        ((Activity)mContext).overridePendingTransition(R.anim.no_animation,R.anim.no_animation);
                    }
                });break;
            case 3:
                viewHolder.wEqualsHImageView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent = new Intent(mContext, PicListActivity.class);
                        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                        mContext.startActivity(intent);
                        ((Activity)mContext).overridePendingTransition(R.anim.no_animation,R.anim.no_animation);
                    }
                });break;
        }
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new MiningBottomAdapter.ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_grid_main_mining,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        actBar(position,holder);
        bindClick(holder,position);
    }

    @Override
    public int getItemCount() {
        return 4;
    }

    class ViewHolder extends RecyclerView.ViewHolder{

        private TextView textView;
        private WEqualsHImageView wEqualsHImageView;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            textView = (TextView)itemView.findViewById(R.id.bottom_bar_text);
            wEqualsHImageView = (WEqualsHImageView)itemView.findViewById(R.id.bottom_bar_icon);
        }
    }
}
